<?php

class Crc_Bootstrap_Resource_Debug extends Zend_Application_Resource_ResourceAbstract
{
    public function init()
    {
        $logger = $this->getBootstrap()->getResource('log');
        $logger->info('Bootstrap ' . __CLASS__);

        if ('production' !== $this->getBootstrap()->getEnvironment())
        {
            $em = $this->getBootstrap()->bootstrap('doctrine')->getResource('doctrine')->getEntityManager();
            $em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\DebugStack());
            $cache = Zend_Registry::get('Zend_Cache_Core');

            $options = array(
                'plugins' => array(
                    'Variables',
                    'ZFDebug_Controller_Plugin_Debug_Plugin_Doctrine2' => array(
                        'entityManagers' => array($em),
                    ),
                    'File' => array('basePath' => APPLICATION_PATH),
                    'Cache' => array('backend' => $cache->getBackend()),
                    'Exception',
                    'Html',
                    'Memory',
                    'Time',
                ),
                //'image_path' => APPLICATION_PATH . '../public/media/images/debugbar'
            );

            $debug = new ZFDebug_Controller_Plugin_Debug($options);
            $this->getBootstrap()->bootstrap('frontController');
            $frontController = $this->getBootstrap()->getResource('frontController');
            $frontController->registerPlugin($debug);
        }
    }
}